package com.songshuai.webapi.baseapi.service.impl;

import com.songshuai.webapi.baseapi.dao.BaseChannelDao;
import com.songshuai.webapi.baseapi.dto.crmbase.ChannelDto;
import com.songshuai.webapi.baseapi.model.YixueBaseChannel;
import com.songshuai.webapi.baseapi.service.BaseChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class BaseChannelServiceImpl implements BaseChannelService {

    @Autowired
    private BaseChannelDao channelDao;

    @Override
    public List<ChannelDto> getChannelsByIds(List<Integer> ids) {
        List<ChannelDto> retList=new ArrayList<>();
        if(ids==null||ids.size()==0){
            return retList;
        }
        List<YixueBaseChannel>baseChannels=channelDao.getChannelsByIds(ids);
        if(baseChannels!=null){
            for(YixueBaseChannel channel:baseChannels){
                ChannelDto channelDto=new ChannelDto();
                channelDto.setCn_name(channel.getCn_name());
                channelDto.setId(channel.getId());
                channelDto.setIs_sync(channel.getIs_sync());
                channelDto.setLevel_num(channel.getLevel_num());
                channelDto.setLevel_value(channel.getLevel_value());
                channelDto.setRemark(channel.getRemark());
                channelDto.setSort(channel.getSort());
                channelDto.setType_id(channel.getType_id());
                retList.add(channelDto);
            }
        }
        return retList;
    }

    @Override
    public ChannelDto getChannelById(Integer id) {
        ChannelDto retData=null;
        if(id<=0){
            return  retData;
        }
        List<Integer>channelIds=new ArrayList<>();
        channelIds.add(id);
        List<ChannelDto>channelDtos=getChannelsByIds(channelIds);
        if(channelDtos!=null&&channelDtos.size()>0){
            retData=channelDtos.get(0);
        }
        return retData;
    }

    @Override
    public String getChannelName(Integer id) {
        String retData="";
        if(id<=0){
            return  retData;
        }
        ChannelDto channel=getChannelById(id);
        if(channel!=null){
            retData=channel.getCn_name();
        }
        return retData;
    }
}
